<template>
  <el-container class="full-height">
    <el-header class="header">
      <h1>巡检员后台</h1>
    </el-header>
    <el-container>
      <el-aside width="200px" class="sidebar">
        <el-menu :default-active="activeView" class="custom-menu">
          <el-menu-item @click="changeView('tasks')">
            <el-icon><document /></el-icon>
            <span>巡检任务</span>
          </el-menu-item>
          <el-menu-item @click="changeView('person')">
            <el-icon><user /></el-icon>
            <span>个人信息维护</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main class="content">
        <component :is="currentView"></component>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { defineAsyncComponent } from 'vue';
import { Document, User } from '@element-plus/icons-vue';

// 动态加载组件
const TasksView = defineAsyncComponent(() => import('@/views/TaskView.vue'));
const PersonalInfoView = defineAsyncComponent(() => import('@/views/PersonalInfo.vue'));

export default {
  name: 'InspectorLayout',
  components: {
    Document,
    User
  },
  data() {
    return {
      activeView: 'tasks', // 默认显示巡检任务
      currentView: TasksView,
    };
  },
  methods: {
    changeView(viewName) {
      this.activeView = viewName;

      // 根据 viewName 动态切换组件
      switch (viewName) {
        case 'tasks':
          this.currentView = TasksView;
          break;
        case 'person':
          this.currentView = PersonalInfoView;
          break;
        default:
          this.currentView = TasksView;
      }
    },
  },
};
</script>

<style scoped>
.full-height {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: white;
  border-bottom: 1px solid #e0e0e0;
  color: #333;
  text-align: center;
  padding: 0 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.sidebar {
  background-color: white;
  border-right: 1px solid #e0e0e0;
  height: 100%;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
}

.content {
  background-color: white;
  padding: 20px;
  flex: 1;
  overflow-y: auto;
  border-left: 1px solid #e0e0e0;
}

.custom-menu {
  height: 100%;
  border-right: none;
  background-color: white;
}

.el-menu-item {
  height: 60px;
  line-height: 60px;
  font-size: 16px;
  margin-bottom: 5px;
  color: #333;
}

.el-menu-item:hover {
  background-color: #f9f9f9;
  border-left: 4px solid #ccc;
}

.el-menu-item.is-active {
  background-color: #f5f5f5;
  border-left: 4px solid #999;
  font-weight: bold;
}

.el-icon {
  margin-right: 10px;
  width: 24px;
  text-align: center;
  font-size: 18px;
  color: #666;
}
</style>